<template>
  <div class="app-content app-search-list">
    <van-nav-bar @click-left="$router.go(-1);" class="app-van-nav-bar">
      <template #title>
        <van-field v-model="searchForm.courseName" placeholder="搜索课程名字" class="app-van-nav-bar-field" @keyup.enter.native="getList(1)">
          <template #button>
            <x-svg-icon name="search" @click="getList(1)" />
          </template>
        </van-field>
      </template>
      <x-svg-icon slot="left" name="arrow_back" />
      <div slot="right" @click="$router.go(-1);">取消</div>
    </van-nav-bar>
    <x-app-course-list :loading.sync="isLoading" :refreshLoading.sync="refreshLoading" :finished="finished" :list="list" @load="getList">
    </x-app-course-list>
  </div>
</template>

<script>
export default {
  name: 'appSearchList',
  data() {
    return {
      searchForm: {
        currentPage: 1,
        pageSize: 9,
      },
      isLoading: false,
      refreshLoading: false,
      finished: false,
      list: [],
      total: 0,
    };
  },
  methods: {
    async getList (page) {
      this.isLoading = true
      if (page === 1) {
        this.finished = false;
        this.searchForm.currentPage = 1;
        this.list = []
      }
      const { data, total } = await this.Request.getCourseInfoPage({ params: this.searchForm })
      this.list.push(...data);
      this.total = total;
      if(this.list.length >= total) this.finished = true;
      this.searchForm.currentPage++;
      this.isLoading = false;
      this.refreshLoading = false;
    },
  },
  mounted() {
  }
};
</script>

<style lang="scss" scoped>
@import "@/css/variable.scss";
/deep/.app-search-list {
  .van-nav-bar__title {
    width: 70%;
    max-width: 70%;
  }
  .app-van-nav-bar-field {
    width: 100%;
    height: 30px;
    border-radius: 15px;
    background-color: $white6;
    padding: 0 16px;
    .van-cell__value {
      height: 100%;
      .van-field__body {
        height: 100%;
        input {
          height: 100%;
        }
      }
    }
  }
  .van-nav-bar__right {
    color: $white5;
  }
}
</style>
